home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 April: Mac OS SDK / Dev.CD Apr 97 SDK1.toast / Development Kits (Disc 1) / Open Transport / Sample Code / DTS Sample Code / Option Management Samples / EnableEOMSample.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-19  |  2.1 KB  |  78 lines  |  [TEXT/CWIE]

  1. /*
  2.     File: EnableIPReuseAddrSample.c
  3.     By:        Rich Kubota
  4.             Developer Technical Support
  5.     
  6.     Purpose: Demonstrate the use of the OTOptionManagement call to tell an ADSP
  7.             endpoint to enable/disable the EOM option.
  8. */
  9.  
  10. #include <OpenTransport.h>            // open transport files            
  11. #include <OpenTptAppletalk.h>
  12.  
  13. OSStatus DoNegotiateEOMOption(EndpointRef ep, Boolean enableEOM);
  14.  
  15. /*
  16.     Sample function to enable/disable the EOM option for 
  17.     ADSP.  This function also demonstrates the
  18.     use of the OTOptionManagement call.
  19.     
  20.     Unless explicitely defined by XTI, all Open Transport options
  21.     use a kOTFourByteOptionSize buffer.
  22.     
  23.     Input
  24.     EndpointRef ep - endpoint on which to set EOM option on
  25.     Boolean enableEOM - true - option on, false - option off
  26.  
  27.    Return: kOTNoError indicates that the option was successfully negotiated
  28.                OSStatus is an error if < 0, otherwise, the status field is
  29.                returned and is > 0.
  30.     
  31. */
  32. OSStatus DoNegotiateEOMOption(EndpointRef ep, Boolean enableEOM)
  33.  
  34. {
  35.     UInt8        buf[kOTFourByteOptionSize];    // define buffer for fourByte Option size
  36.     TOption*    opt;                        // option ptr to make items easier to access
  37.     TOptMgmt    req;
  38.     TOptMgmt    ret;
  39.     OSStatus    err;
  40.     Boolean        isAsync = false;
  41.     
  42.     opt = (TOption*)buf;                    // set option ptr to buffer
  43.     req.opt.buf    = buf;
  44.     req.opt.len    = sizeof(buf);
  45.     req.flags    = T_NEGOTIATE;                // negotiate for EOM option
  46.  
  47.     ret.opt.buf = buf;
  48.     ret.opt.maxlen = kOTFourByteOptionSize;
  49.     
  50.     opt->level    = ATK_ADSP;                    // dealing with ADSP
  51.     opt->name    = OPT_ENABLEEOM;
  52.     opt->len    = kOTFourByteOptionSize;
  53.     opt->status = 0;
  54.     *(UInt32*)opt->value = enableEOM;        // set the desired option level, true or false
  55.  
  56.     if (OTIsSynchronous(ep) == false)            // check whether ep sync or not
  57.     {
  58.         isAsync = true;                        // set flag if async
  59.         OTSetSynchronous(ep);                    // set endpoint to sync    
  60.     }
  61.                 
  62.     err = OTOptionManagement(ep, &req, &ret);
  63.     
  64.     if (isAsync == true)                    // restore ep state if necessary
  65.         OTSetAsynchronous(ep);
  66.  
  67.         // if no error then return the option status value
  68.     if (err == kOTNoError)
  69.     {
  70.         if (opt->status != T_SUCCESS)
  71.             err = opt->status;
  72.         else
  73.             err = kOTNoError;
  74.     }
  75.         
  76.     return err;
  77. }
  78.